<extend name="layout/index" />
<block name="content">
    <link rel="stylesheet" href="/static/admin/css/font-awesome.css" />
    <link rel="stylesheet" href="/static/admin/css/style.css" />
    <link rel="stylesheet" href="/static/admin/css/plugins/summernote/summernote.css" />
    <link rel="stylesheet" href="/static/admin/css/plugins/summernote/summernote-bs3.css" />

    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>新闻编辑</h5>
                    </div>
                    <div class="ibox-content wrapper wrapper-content" style="display: table">

                        <form role="form" class="form-horizontal m-t">
                            <input type="hidden" name="id" value="{$info.id}">
                            <input type="hidden" id="contents" name="content" value="">
                            <div class="form-group draggable">
                                <div class="col-sm-12">
                                    <div class="summernote">{$info.content|raw}</div>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">新闻标题：</label>
                                <div class="col-sm-7">
                                    <input type="text" name="title" class="form-control" value="{$info.title}" placeholder="请输入新闻标题">
                                    <span class="help-block m-b-none"></span>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">新闻描述：</label>
                                <div class="col-sm-7">
                                    <textarea  name="des" class="form-control" placeholder="新闻描述">{$info.des}</textarea>
                                    <span class="help-block m-b-none">在列表展示的内容</span>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">新闻分类：</label>
                                <div class="col-sm-7">
                                    <select class="form-control" name="cate_id">
                                        <volist name="cate" id="vo">
                                        <option value="{$vo.id}" <if ($vo['id']==$info['cate_id']) >selected</if>  >{$vo.title}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">新闻url：</label>
                                <div class="col-sm-7">
                                    <input type="text" name="url" class="form-control" value="{$info.url}" placeholder="请输入新闻url">
                                    <div class="alert alert-warning">注意！当填写URL时，访问就跳转链接，不再查看填写的新闻内容。</div>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">状态</label>
                                <div class="col-sm-7">
                                    <label class="radio-inline">
                                        <input type="radio" checked="" value="1" name="status"> 显示
                                    </label>
                                    <label class="radio-inline"><input type="radio" value="0"  name="status">隐藏</label>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">发布时间：</label>
                                <div class="col-sm-7">
                                    <input type="text" name="publish_time" class="form-control layui-input"  id="publish_time" value="<gt name='info.publish_time' value='0'>{$info.publish_time|date='Y-m-d H:i:s'}</gt>" readonly placeholder="选择发布时间">
                                    <div class="alert alert-warning">注意！不选择发布时间，就会默认显示当前提交的时间。</div>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">排序：</label>
                                <div class="col-sm-7">
                                    <input type="text" name="sort" class="form-control layui-input"   value="{$info.sort}"  placeholder="选择发布时间">
                                    <div class="alert alert-warning">注意！数字越大，就越排在前面。</div>
                                </div>
                            </div>
                            <div class="form-group draggable">
                                <label class="col-sm-2">新闻图片：</label>
                                <div class="input-file-show col-sm-4">
                                    <input type="hidden" id="image" name="image" value="{$info.image}" class="type-file-text">
                                    <input type="button" name="button" value="选择上传..." onclick="GetUploadify('img_call_back')" class="type-file-button layui-btn">
                                    <div class="help-block am-margin-top-sm">
                                        <small>尺寸150x150像素以上，大小2M以下</small>
                                    </div>
                                    <div class="putrue">
                                        <img id="userimg_i" class="fa fa-picture-o" src="{$info.image}" alt="" />
                                    </div>
                                </div>

                            </div>

                            <div class="hr-line-dashed"></div>
                            <div class="form-group draggable" style="margin-bottom: 20px;">
                                <div class="col-sm-7 col-sm-offset-3">
                                    <button class="btn btn-primary" type="button">保存内容</button>
                                    <button class="btn btn-white" type="submit">取消</button>
                                </div>
                            </div>
                            <div class="clearfix"></div>
                        </form>

                    </div>
                </div>
            </div>

        </div>
    </div>
</block>

<block name="js">

    <script src="/static/admin/js/plugins/summernote/summernote.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/admin/js/plugins/summernote/summernote-zh-CN.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/admin/js/plugins/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script>
        $(document).ready(function() {
            //HTML编辑器
            $('.summernote').summernote({
                lang : 'zh-CN',
                onblur : function(e) {
                    var sHTML = $('.summernote').code();
                    $("#contents").val(sHTML);
                },
                height:"300px",
                width:"1000px",
                focus: true,
            });

         layui.use('laydate', function(){
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#publish_time' //指定元素
                    ,type: 'datetime'
                });
            });
        });
        $(".btn-primary").click(function(){
            //   alert($("form").serialize());
            $.ajax({
                type : "post",
                url : "{:url('news/edit')}",
                data : $("form").serialize(),
                dataType : "json",
                success : function(data) {
                    layer.msg(data.msg);
                    if (data.code==1) {
                        location.href=data.url;;
                    }
                },
                error : function(err) {
                    layer.alert(err.info, 8);
                }
            });
        })
        //上传文件后，更改路径
        function img_call_back(fileurl_tmp) {
            $("#image").val(fileurl_tmp);
            $("#userimg_i").attr('src', fileurl_tmp); //layer.open('<img src="+fileurl_tmp+">',this,{tips: [1, '#fff']});
        };
    </script>
</block>